/**
 * @Author: xzm
 * @Date: 2019/9/10
 */
import axios from '@/api/fetch';
import SERVER from '@/api/server';
import {
  getAppId,
  getCompanyId
} from '@/assets/js/auth';

// 操作记录 /ttFiTripartiteApply/selectLog?id=1
export const queryLog = (Id) => axios.get(`${SERVER.WHOLESALES}/ttFiTripartiteApply/selectLog?id=${Id}`)


// 上级仓库列表
export const getFactoryWarehouseList = (params) => axios.get(`${SERVER.WHOLESALES}/tmVsSubWarehouse/getWarehouseList`, {
  params
})

// 资金账户类型
export const getFiAccountType = (params) => axios.post(`${SERVER.WHOLESALES}/tmFiAccountType/list`, params)

// 获取订单细分类型
export const getNotPage = (params) => axios.get(`${SERVER.WHOLESALES}/fiOrderTypeSub/searchFiOrderTypeSubDTOListNotPage`, {
  params
})

// 车辆配置五级选择
export const vehicleConfiguration = (id, params) => axios.get(`${SERVER.BASEDATA}/vehicleProduct/productInfo/productTreeNew`, {
  params: {
    type: id,
    level: 6,
    ...params
  }
});
// 整车编码查询
export const getVehicleInfo = (params) => axios.get(`${SERVER.BASEDATA}/vehicleProduct/productInfo/getInfo`, {
  params
})

// 查询所有经销商
export const getDealerUser = params => axios.get(`${SERVER.DMSCLOUD_BASEDATA}/basedata/users/getAllUser`);

//  查询销售顾问	sysmanage	 /employeeNew/getEmployees	get
export const getEmployees = (params) => axios.get(`${SERVER.SYSMANAGE}/employeeNew/getEmployees`, {
  params
});

// 厂端 经销商信息查询接口  /api/cmscloud.channel/message/dealerAttach
export const dealerAttach = (params) => axios.get(`${SERVER.CMSCLOUD_CHANNEL}/message/dealerAttach`, {
  params
});
// 厂端 经销商信息查询接口，获取所有数据
export const getDealerAll = (params) => axios.get(`${SERVER.CMSCLOUD_CHANNEL}/message/dealerAttach/dealerInfo/getDealerAll`, {
  params
});
export const downloadModel = params => {
  const url = `${SERVER.CMSCLOUD_CHANNEL}/message/dealerAttach/dealerInfo/downloadDealersExcel`;
  return axios({
    url,
    method: 'get',
    responseType: 'blob'
  });
};
export const downloadOptionModel = params => {
  const url = `${SERVER.BASEDATA}/vehicleProduct/downloadUseModelExcel`;
  return axios({
    url,
    method: 'get',
    responseType: 'blob'
  });
};
// 根据事业部id，查询事业部下经销商所包含的省份id
export const getProvinceByDeptId = (params) => axios.get(`${SERVER.CMSCLOUD_CHANNEL}/message/dealerAttach/getProvinceByDeptId`, {
  params
});
//根据当前登录用户所在事业部id，查询事业部下经销商所包含的省份id
export const getProvinceByLoginDeptId = (params) => axios.get(`${SERVER.CMSCLOUD_CHANNEL}/message/dealerAttach/getProvinceByLoginDeptId`, {
  params
});

function getCustomCompanyId() {
  let appId = getAppId();
  //根据登录信息获取登录人所属车厂公司
  //let companyId = getCompanyId();
  let companyId = "";
  // if (appId == 'arcfox') {
  //   companyId = 35; // 45
  // } else {
  //   companyId = 35; // 46
  // }
  return companyId;
}

//获取大区（事业部）--销售大区
export const getRegion = async (params) => {
  let para = Object.assign({}, params, {
    "orgType": 15061005,
    "companyId": getCompanyId()
  })
  let rlist = await axios.get(`${SERVER.DMSCLOUD_BASEDATA}/org/getOrgByOrgType4cms`, {
    params: para
  });
  if (rlist.resultCode == 200) {
    if (rlist.data && rlist.data != null && rlist.data.length > 0) {
      for (let i = 0; i < rlist.data.length; i++) {
        rlist.data[i].id = rlist.data[i].orgId;
      }
    }
  }
  return rlist;
};

//获取小区（办事处）--销售小区
export const getCommunity = async (areaId) => {
  let para = Object.assign({}, {
    "orgType": 15061007,
    "companyId": getCompanyId(),
    "parentOrgId": areaId
  })
  let rlist = await axios.get(`${SERVER.DMSCLOUD_BASEDATA}/org/getOrgByOrgType4cms`, {
    params: para
  });
  if (rlist.resultCode == 200) {
    if (rlist.data && rlist.data != null && rlist.data.length > 0) {
      for (let i = 0; i < rlist.data.length; i++) {
        rlist.data[i].id = rlist.data[i].orgId;
      }
    }
  }
  return rlist;
}

//获取大区（事业部）--销售大区,以“，”分割字符串
export const getRegionString = async (params) => {
  let para = Object.assign({}, params, {
    "orgType": 15061005,
    "companyId": getCompanyId()
  })
  let rlist = await axios.get(`${SERVER.DMSCLOUD_BASEDATA}/org/getOrgByOrgType4cms`, {
    params: para
  });
  let results = [];
  if (rlist.resultCode == 200) {
    if (rlist.data && rlist.data != null && rlist.data.length > 0) {
      for (let i = 0; i < rlist.data.length; i++) {
        results.push(rlist.data[i].orgId);
      }
    }
  }
  return results.join(",");
};
